package zjc.bookkeeping.minepage.aAssetaccount;

import static com.mob.MobSDK.getContext;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;

import zjc.bookkeeping.R;
import zjc.bookkeeping.db.AccountBean;
import zjc.bookkeeping.db.DBManager;
import zjc.bookkeeping.db.MethodBean;

public class AssetreviseaccountActivity extends AppCompatActivity {
    EditText name;
    EditText remoney;
    EditText reremark;
    EditText recard;

    int extraid;
    MethodBean methodBean;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_assetreviseaccount);

        name=findViewById(R.id.rename);
        remoney=findViewById(R.id.remoney);
        reremark=findViewById(R.id.reremark);
        recard=findViewById(R.id.recard);
        Modifydetail();
    }

    public void back(View v){
        finish();
        Toast.makeText(this, "取消修改", Toast.LENGTH_SHORT).show();
    }


    private void Modifydetail(){

        //获取传递的字符串值
        Intent intent =getIntent();
        extraid= intent.getIntExtra("accountid",0);


        System.out.println("3.extraid:"+extraid);
        List<MethodBean> list= DBManager.getMethodbyid(extraid);
        int k=list.size();
        System.out.println("listk:"+k);
        if(k==1){
            System.out.println("0"+"账户:"+list.get(0).getMethod_id()+" "+list.get(0).getMethod_name()+" "+list.get(0).getMethod_money()+" "+list.get(0).getMethod_remark()+" "+list.get(0).getMethod_card());
            String money= String.valueOf(list.get(0).getMethod_money());
            name.setText(list.get(0).getMethod_name());
            remoney.setText(money);
            reremark.setText(list.get(0).getMethod_remark());
            recard.setText(list.get(0).getMethod_card());

        }
    }

    public void sure(View v){
        finish();
        methodBean=new MethodBean();
        methodBean.setMethod_id(extraid);
        methodBean.setMethod_name(name.getText().toString());
        methodBean.setMethod_money(Float.parseFloat(remoney.getText().toString()));
        methodBean.setMethod_remark(reremark.getText().toString());
        methodBean.setMethod_card(recard.getText().toString());
        DBManager.updateMethodbyid(methodBean);
        Toast.makeText(this, "修改成功，请下拉刷新", Toast.LENGTH_SHORT).show();
    }
}